package com.sakura.probe.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 开启swagger
 * @author Sakura
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 配置Swagger配置
     * RequestHandlerSelectors.配置要扫描接口的方式
     * any():全部扫描
     * none():不扫描
     * withClassAnnotation:扫描类上的注解,参数是一个注解的反射对象
     * withMethodAnnotation:扫描方法上的注解
     *
     * PathSelectors.配置如何通过path过滤
     * any():任何请求都扫描
     * none():任何请求都不扫描
     * regex(final String pathRegex):通过正则表达式控制
     * ant(final String antPattern):通过ant()控制
     * @return
     */
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sakura.probe.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置Swagger信息
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("probe-admin")
                .description("probe-admin相关API——SwaggerUI")
                .version("1.0")
                .build();
    }

}
